package com.ww.springboot.boot.thread.study.base.lock.aqs.demo.lock1;

import com.ww.springboot.boot.thread.study.base.lock.aqs.source.MyAbstractQueuedSynchronizer;

public class MySync extends MyAbstractQueuedSynchronizer {

    @Override
    protected boolean tryAcquire(int arg) {
        //1.实现每次只允许1个线程获取锁
        if (compareAndSetState(0, 1)) {
            return true;
        }
        return false;
    }

    @Override
    protected boolean tryRelease(int arg) {
        if (compareAndSetState(1, 0)) {
            return true;
        }
        return false;
    }

    public MyAbstractQueuedSynchronizer.ConditionObject conditionObject() {
        return new ConditionObject();
    }
}